#include<stdio.h>
#include<stdlib.h>
#include<at89c51ed2.h>
#include <mcs51reg.h>

/*This function implements the virtual debug port functionality. When called, the function calls
 * a pointer pointing to pre-defined address(0xFFFF as required). The input integer parameter value
 * is then forced at that location. Thus, a data write operation at a non-physical address is 
 * executed. This can be picked up on the logic analyser when this function is called in between
 * program execution for debugging.*/


void lcdData(char val,int reg)__critical
{	
	
	if(reg==0){
	
	xdata char volatile *test;   //pointer pointing to an address in xdata space 
	test=(xdata char*)0xF000; //assigning specific address 0xFFFF to pointer
	P0_1=1;	
	*test=val;//debug data value 
	}
	if(reg==1){
	
	xdata char volatile *test;   //pointer pointing to an address in xdata space 
	test=(xdata char*)0xF001; //assigning specific address 0xFFFF to pointer
	P0_1=1;	
	*test=val;//debug data value 
	}
	
	


}



int lcdDataRead()
{	

	int val;
	
	xdata int volatile *test;
	
	test=(xdata int*)0xF002; //assigning specific address 0xFFFF to pointer
	val=*test;/*debug data value */
	lcdData(0x10,0);
	//lcdData(0x0F,0);
	return val;
	
} 
